#define _WIN32_DCOM
#include <windows.h>
#include <iostream.h>
#include <stdio.h>

void main()
{
	HRESULT hr = 0;
	CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

    ITypeLib* pTypeLib = 0;
	GUID LIBID_Component = {0x10000003,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}};
    LoadRegTypeLib(LIBID_Component, 1, 0, LANG_NEUTRAL, &pTypeLib);

	TLIBATTR* r = 0;
	pTypeLib->GetLibAttr(&r);

	OLECHAR string[255];
	StringFromGUID2(r->guid, string, 255);
	wprintf(L"LIBID = %s\n", string);

	if(r->syskind == SYS_WIN32)
		cout << "syskind = SYS_WIN32" << endl;

	switch(r->wLibFlags)
	{
	case LIBFLAG_FRESTRICTED:
		cout << "wLibFlags = LIBFLAG_FRESTRICTED" << endl;
		break;
	case LIBFLAG_FCONTROL:
		cout << "wLibFlags = LIBFLAG_FCONTROL" << endl;
		break;
	case LIBFLAG_FHIDDEN:
		cout << "wLibFlags = LIBFLAG_FHIDDEN" << endl;
		break;
	}

	cout << "Version major = " << r->wMajorVerNum << " minor = " << r->wMinorVerNum << endl;
	cout << "Locale ID = " << r->lcid << endl;
	pTypeLib->ReleaseTLibAttr(r);

	CLSID CLSID_InsideCOM = {0x10000002,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}};

	ITypeInfo* pTypeInfo = 0;
	IID IID_ISum = {0x10000001,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}};
    hr = pTypeLib->GetTypeInfoOfGuid(IID_ISum, &pTypeInfo);

	cout << "Method ISum::Sum" << endl;

	FUNCDESC* pFuncDesc = 0;
	hr = pTypeInfo->GetFuncDesc(0, &pFuncDesc);
	cout << "memid = " << pFuncDesc->memid << endl;
	cout << pFuncDesc->cParams << " parameters" << endl;

	pTypeInfo->ReleaseFuncDesc(pFuncDesc);

	pTypeInfo->Release();
    pTypeLib->Release();

	CoUninitialize();
}